(*
  Copyright (c) 2009 Barry Schwartz

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*)

open XNum
open OpenType
open UniTools
module IntMap : Map.S with type key = int
  
type glyph_desc =
  | Undef
  | Simple of int
  | Raised of int * num
  | Accent of int * int
  | Sequence of int list
  | Extendable of glyph_desc * glyph_desc * glyph_desc * glyph_desc
(* with sexp_of *)

module OrderedGlyphDesc :
sig type t = glyph_desc
    val compare : glyph_desc -> glyph_desc -> int
end
  
module GlyphMap  : Map.S with type key = glyph_desc
module GlyphSet  : Set.S with type elt = glyph_desc
module GlyphTrie : DynamicTrie.S with type elt = glyph_desc

type glyph_text =
  | NoGlyphText
  | GlyphText of UniTools.UniText.t
  | ClusterContinuation
(* with sexp_of *)
  
type ('font, 'box, 'cmd) glyph_item =
    [
    | `Glyph of glyph_desc * 'font * glyph_text
    | `Kern of num * num
    | `Box of 'box
    | `Command of 'cmd
    | `Break of
        num * bool *
          ('font, 'box, 'cmd) glyph_item array *
          ('font, 'box, 'cmd) glyph_item array *
          ('font, 'box, 'cmd) glyph_item array
    ]
(* with sexp_of *)

type ('font, 'box, 'cmd) glyph_composer =
    ('font, 'box, 'cmd) glyph_item list -> ('font, 'box, 'cmd) glyph_item list
(* with sexp_of *)


val get_break_penalty : [> `Break of 'penalty * 'hyph * 'pre * 'post * 'no ] -> 'penalty
val break_is_hyph     : [> `Break of 'penalty * 'hyph * 'pre * 'post * 'no ] -> 'hyph
val get_pre_break     : [> `Break of 'penalty * 'hyph * 'pre * 'post * 'no ] -> 'pre
val get_post_break    : [> `Break of 'penalty * 'hyph * 'pre * 'post * 'no ] -> 'post
val get_no_break      : [> `Break of 'penalty * 'hyph * 'pre * 'post * 'no ] -> 'no
val is_break          : [> `Break of 'anything                             ] -> bool
val is_nonhyph_break  : [> `Break of 'penalty *  bool * 'pre * 'post * 'no ] -> bool

val dump_glyph_text     : glyph_text -> unit
val combine_glyph_texts : glyph_text -> glyph_text -> glyph_text
  
val ot_composer : num ->
  (Tag.t -> Tag.t -> LookupMarker.t) ->
  (Tag.t -> Tag.t -> LookupMarker.t) ->
  'font -> UniText.t -> FeatureSet.t ->
  ('font, 'box, 'cmd) glyph_composer
